package org.yray.somehttp.sseclient;


import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.internal.sse.RealEventSource;
import okhttp3.sse.EventSource;
import okhttp3.sse.EventSourceListener;

public class SseClient {
    public static void main(String[] args) throws InterruptedException {
        OkHttpClient client = new OkHttpClient();
        for(int i=500;i<1000;i++)
        {
            final String s=i+"";
            Thread thread=new Thread(()->{
            String sseUrl = "http://localhost:8099/sse/connect?uid="+s; // 替换为实际的SSE服务端点
            // 创建请求
            Request request = new Request.Builder()
                    .url(sseUrl)
                    .build();
            // 实例化EventSource，注册EventSource监听器
            RealEventSource realEventSource = new RealEventSource(request, new MyEventSourceListener(System.currentTimeMillis()));
            realEventSource.connect(client);//真正开始请求的一步
        });
            thread.start();
    }
        Thread.sleep(5000000);}
}
